<?php
/**
 * Created by PhpStorm.
 * User: sunruohua
 * Date: 2019.04.15
 * Time: 下午 07:19
 */

namespace App\Http\Middleware;

use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Auth;
use Closure;

class isAdmin
{
    public function handle($request, Closure $next)
    {
        //未登录状态，重定向到登录页面
        if (!Auth::guard('web')->check()) {
            return Redirect::route('login');
        } else {
            //过滤其他用户
            if (!Auth::guard('web')->user()->level) {
                session()->flash('message_warning', '您没有管理权限');
                return Redirect::route('login');
            }
        }
        return $next($request);
    }
}